<?php

use App\Enums\OrderPay;
use App\Enums\PayMethod;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->default(0)->comment('用户id');
            $table->unsignedBigInteger('project_id')->default(0)->comment('项目id');
            $table->unsignedBigInteger('material_id')->default(0)->comment('资料id');
            $table->unsignedTinyInteger('pay_method')->default(PayMethod::ALI)->comment('支付方式:0=支付宝,1=微信');
            $table->decimal('money', 20)->default(0.00)->comment('支付金额');
            $table->string('order_no')->default('')->comment('平台订单号');
            $table->string('trade_no')->default('')->comment('第三方订单号');
            $table->unsignedTinyInteger('pay')->default(OrderPay::WAIT)->comment('支付状态:0=未支付,1=已支付,2=过期');
            $table->timestamp('pay_time')->nullable()->comment('支付时间');
            $table->timestamp('pay_expired_time')->nullable()->comment('支付过期时间');
            $table->text('project_info')->nullable()->comment('项目信息');
            $table->text('pay_param')->nullable()->comment('支付参数');
            $table->text('pay_response')->nullable()->comment('支付响应');
            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
};
